package javbot.gui;

import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

public class KeyPanel extends JPanel {

	private static final long serialVersionUID = -2810195209996803964L;
	private JToggleButton jtbShift = null;
	private JToggleButton jtbCtrl = null;
	private JToggleButton jtbAlt = null;
	private JToggleButton jtbWinKey = null;
	private JToggleButton jtbEsc = null;
	private JToggleButton jtbEnter = null;
	private JToggleButton jtbBackspace = null;
	private JToggleButton jtbSpace = null;
	private JToggleButton jtbTab = null;
	private JToggleButton jtbKeyA = null;
	private JToggleButton jtbKeyB = null;
	private JToggleButton jtbKeyC = null;
	private JToggleButton jtbKeyD = null;
	private JToggleButton jtbKeyE = null;
	private JToggleButton jtbKeyF = null;
	private JToggleButton jtbKeyG = null;
	private JToggleButton jtbKeyH = null;
	private JToggleButton jtbKeyI = null;
	private JToggleButton jtbKeyJ = null;
	private JToggleButton jtbKeyK = null;
	private JToggleButton jtbKeyL = null;
	private JToggleButton jtbKeyM = null;
	private JToggleButton jtbKeyN = null;
	private JToggleButton jtbKeyO = null;
	private JToggleButton jtbKeyP = null;
	private JToggleButton jtbKeyQ = null;
	private JToggleButton jtbKeyR = null;
	private JToggleButton jtbKeyS = null;
	private JToggleButton jtbKeyT = null;
	private JToggleButton jtbKeyU = null;
	private JToggleButton jtbKeyV = null;
	private JToggleButton jtbKeyW = null;
	private JToggleButton jtbKeyX = null;
	private JToggleButton jtbKeyY = null;
	private JToggleButton jtbKeyZ = null;
	private JLabel jLabelCurrentSelection = null;

	public ArrayList<String> buttons = new ArrayList<String>();
	private ActionListener actionListener = new ActionListener() {
		public void actionPerformed(java.awt.event.ActionEvent e) {
			
			JToggleButton but =	(JToggleButton) e.getSource();
			if (but.isSelected()) {
				buttons.add(but.getText());
			}
			else {
				buttons.remove(but.getText());
			}
			
			Iterator<String> it = buttons.iterator();
			String st = "";
			while (it.hasNext()) {
				st +=  it.next();
				if (it.hasNext())
					st +=  " + ";
			}
			
			jLabelCurrentSelection.setText(st);			
		}
	};
	private JButton jButtonOK = null;
	private JLabel jLabel = null;
	private JButton jButtonCancel = null;
	
	/**
	 * This is the default constructor
	 */
	public KeyPanel() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabel = new JLabel();
		jLabel.setBounds(new java.awt.Rectangle(6,234,107,24));
		jLabel.setText("Key Combination:");
		jLabelCurrentSelection = new JLabel();
		jLabelCurrentSelection.setBounds(new java.awt.Rectangle(116,233,321,26));
		jLabelCurrentSelection.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 14));
		jLabelCurrentSelection.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		jLabelCurrentSelection.setForeground(java.awt.Color.blue);
		jLabelCurrentSelection.setText("");
		this.setLayout(null);
		this.setSize(451, 348);
		this.add(getJtbShift(), null);
		this.add(getJtbCtrl(), null);
		this.add(getJtbAlt(), null);
		this.add(getJtbWinKey(), null);
		this.add(getJtbEsc(), null);
		this.add(getJtbEnter(), null);
		this.add(getJtbBackspace(), null);
		this.add(getJtbSpace(), null);
		this.add(getJtbTab(), null);
		this.add(getJtbKeyA(), null);
		this.add(getJtbKeyB(), null);
		this.add(getJtbKeyC(), null);
		this.add(getJtbKeyD(), null);
		this.add(getJtbKeyE(), null);
		this.add(getJtbKeyF(), null);
		this.add(getJtbKeyG(), null);
		this.add(getJtbKeyH(), null);
		this.add(getJtbKeyI(), null);
		this.add(getJtbKeyJ(), null);
		this.add(getJtbKeyK(), null);
		this.add(getJtbKeyL(), null);
		this.add(getJtbKeyM(), null);
		this.add(getJtbKeyN(), null);
		this.add(getJtbKeyO(), null);
		this.add(getJtbKeyP(), null);
		this.add(getJtbKeyQ(), null);
		this.add(getJtbKeyR(), null);
		this.add(getJtbKeyS(), null);
		this.add(getJtbKeyT(), null);
		this.add(getJtbKeyU(), null);
		this.add(getJtbKeyV(), null);
		this.add(getJtbKeyW(), null);
		this.add(getJtbKeyX(), null);
		this.add(getJtbKeyY(), null);
		this.add(getJtbKeyZ(), null);
		this.add(jLabelCurrentSelection, null);
		this.add(getJButtonOK(), null);
		this.add(jLabel, null);
		this.add(getJButtonCancel(), null);
	}

	/**
	 * This method initializes jtbShift	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbShift() {
		if (jtbShift == null) {
			jtbShift = new JToggleButton();
			jtbShift.setBounds(new java.awt.Rectangle(15,10,72,26));
			jtbShift.setText("SHIFT");
			jtbShift.addActionListener(actionListener);
		}
		return jtbShift;
	}

	/**
	 * This method initializes jtbCtrl	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbCtrl() {
		if (jtbCtrl == null) {
			jtbCtrl = new JToggleButton();
			jtbCtrl.setBounds(new java.awt.Rectangle(15,80,72,26));
			jtbCtrl.setText("CTRL");
			jtbCtrl.addActionListener(actionListener);
		}
		return jtbCtrl;
	}

	/**
	 * This method initializes jtbAlt	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbAlt() {
		if (jtbAlt == null) {
			jtbAlt = new JToggleButton();
			jtbAlt.setBounds(new java.awt.Rectangle(15,43,72,26));
			jtbAlt.setText("ALT");
			jtbAlt.addActionListener(actionListener);
		}
		return jtbAlt;
	}

	/**
	 * This method initializes jtbWinKey	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbWinKey() {
		if (jtbWinKey == null) {
			jtbWinKey = new JToggleButton();
			jtbWinKey.setBounds(new java.awt.Rectangle(47,117,108,26));
			jtbWinKey.setText("WINKEY");
			jtbWinKey.addActionListener(actionListener);
		}
		return jtbWinKey;
	}

	/**
	 * This method initializes jtbEsc	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbEsc() {
		if (jtbEsc == null) {
			jtbEsc = new JToggleButton();
			jtbEsc.setBounds(new java.awt.Rectangle(112,8,72,26));
			jtbEsc.setText("ESC");
			jtbEsc.addActionListener(actionListener);
		}
		return jtbEsc;
	}

	/**
	 * This method initializes jtbEnter	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbEnter() {
		if (jtbEnter == null) {
			jtbEnter = new JToggleButton();
			
			jtbEnter.setBounds(new java.awt.Rectangle(112,79,72,26));
			jtbEnter.setText("ENTER");
			jtbEnter.addActionListener(actionListener);
		}
		return jtbEnter;
	}

	/**
	 * This method initializes jtbBackspace	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbBackspace() {
		if (jtbBackspace == null) {
			jtbBackspace = new JToggleButton();
			jtbBackspace.setBounds(new java.awt.Rectangle(47,151,108,28));
			jtbBackspace.setText("BACKSPACE");
			jtbBackspace.addActionListener(actionListener);
		}
		return jtbBackspace;
	}

	/**
	 * This method initializes jtbSpace	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbSpace() {
		if (jtbSpace == null) {
			jtbSpace = new JToggleButton();
			jtbSpace.setBounds(new java.awt.Rectangle(47,184,108,26));
			jtbSpace.setText("SPACE");
			jtbSpace.addActionListener(actionListener);
		}
		return jtbSpace;
	}

	/**
	 * This method initializes jtbTab	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbTab() {
		if (jtbTab == null) {
			jtbTab = new JToggleButton();
			jtbTab.setBounds(new java.awt.Rectangle(112,42,72,26));
			jtbTab.setText("TAB");
			jtbTab.addActionListener(actionListener);
		}
		return jtbTab;
	}

	/**
	 * This method initializes jtbKeyA	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyA() {
		if (jtbKeyA == null) {
			jtbKeyA = new JToggleButton();
			jtbKeyA.setBounds(new java.awt.Rectangle(215,11,51,22));
			jtbKeyA.setText("A");
			jtbKeyA.addActionListener(actionListener);
		}
		return jtbKeyA;
	}

	/**
	 * This method initializes jtbKeyB	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyB() {
		if (jtbKeyB == null) {
			jtbKeyB = new JToggleButton();
			jtbKeyB.setBounds(new java.awt.Rectangle(269,11,51,22));
			jtbKeyB.setText("B");
			jtbKeyB.addActionListener(actionListener);
		}
		return jtbKeyB;
	}

	/**
	 * This method initializes jtbKeyC	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyC() {
		if (jtbKeyC == null) {
			jtbKeyC = new JToggleButton();
			jtbKeyC.setBounds(new java.awt.Rectangle(323,11,51,22));
			jtbKeyC.setText("C");
			jtbKeyC.addActionListener(actionListener);
		}
		return jtbKeyC;
	}

	/**
	 * This method initializes jtbKeyD	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyD() {
		if (jtbKeyD == null) {
			jtbKeyD = new JToggleButton();
			jtbKeyD.setBounds(new java.awt.Rectangle(377,11,51,22));
			jtbKeyD.setText("D");
			jtbKeyD.addActionListener(actionListener);
		}
		return jtbKeyD;
	}

	/**
	 * This method initializes jtbKeyE	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyE() {
		if (jtbKeyE == null) {
			jtbKeyE = new JToggleButton();
			jtbKeyE.setBounds(new java.awt.Rectangle(215,39,51,22));
			jtbKeyE.setText("E");
			jtbKeyE.addActionListener(actionListener);
		}
		return jtbKeyE;
	}

	/**
	 * This method initializes jtbKeyF	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyF() {
		if (jtbKeyF == null) {
			jtbKeyF = new JToggleButton();
			jtbKeyF.setBounds(new java.awt.Rectangle(269,39,51,22));
			jtbKeyF.setText("F");
			jtbKeyF.addActionListener(actionListener);
		}
		return jtbKeyF;
	}

	/**
	 * This method initializes jtbKeyG	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyG() {
		if (jtbKeyG == null) {
			jtbKeyG = new JToggleButton();
			jtbKeyG.setBounds(new java.awt.Rectangle(323,39,51,22));
			jtbKeyG.setText("G");
			jtbKeyG.addActionListener(actionListener);
		}
		return jtbKeyG;
	}

	/**
	 * This method initializes jtbKeyH	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyH() {
		if (jtbKeyH == null) {
			jtbKeyH = new JToggleButton();
			jtbKeyH.setBounds(new java.awt.Rectangle(377,39,51,22));
			jtbKeyH.setText("H");
			jtbKeyH.addActionListener(actionListener);
		}
		return jtbKeyH;
	}

	/**
	 * This method initializes jtbKeyI	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyI() {
		if (jtbKeyI == null) {
			jtbKeyI = new JToggleButton();
			jtbKeyI.setBounds(new java.awt.Rectangle(215,67,51,22));
			jtbKeyI.setText("I");
			jtbKeyI.addActionListener(actionListener);
		}
		return jtbKeyI;
	}

	/**
	 * This method initializes jtbKeyJ	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyJ() {
		if (jtbKeyJ == null) {
			jtbKeyJ = new JToggleButton();
			jtbKeyJ.setBounds(new java.awt.Rectangle(269,67,51,22));
			jtbKeyJ.setText("J");
			jtbKeyJ.addActionListener(actionListener);
		}
		return jtbKeyJ;
	}

	/**
	 * This method initializes jtbKeyK	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyK() {
		if (jtbKeyK == null) {
			jtbKeyK = new JToggleButton();
			jtbKeyK.setBounds(new java.awt.Rectangle(323,67,51,22));
			jtbKeyK.setText("K");
			jtbKeyK.addActionListener(actionListener);
		}
		return jtbKeyK;
	}

	/**
	 * This method initializes jtbKeyL	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyL() {
		if (jtbKeyL == null) {
			jtbKeyL = new JToggleButton();
			jtbKeyL.setBounds(new java.awt.Rectangle(377,67,51,22));
			jtbKeyL.setText("L");
			jtbKeyL.addActionListener(actionListener);
		}
		return jtbKeyL;
	}

	/**
	 * This method initializes jtbKeyM	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyM() {
		if (jtbKeyM == null) {
			jtbKeyM = new JToggleButton();
			jtbKeyM.setBounds(new java.awt.Rectangle(215,95,51,22));
			jtbKeyM.setText("M");
			jtbKeyM.addActionListener(actionListener);
		}
		return jtbKeyM;
	}

	/**
	 * This method initializes jtbKeyN	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyN() {
		if (jtbKeyN == null) {
			jtbKeyN = new JToggleButton();
			jtbKeyN.setBounds(new java.awt.Rectangle(269,95,51,22));
			jtbKeyN.setText("N");
			jtbKeyN.addActionListener(actionListener);
		}
		return jtbKeyN;
	}

	/**
	 * This method initializes jtbKeyO	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyO() {
		if (jtbKeyO == null) {
			jtbKeyO = new JToggleButton();
			jtbKeyO.setBounds(new java.awt.Rectangle(323,95,51,22));
			jtbKeyO.setText("O");
			jtbKeyO.addActionListener(actionListener);
		}
		return jtbKeyO;
	}

	/**
	 * This method initializes jtbKeyP	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyP() {
		if (jtbKeyP == null) {
			jtbKeyP = new JToggleButton();
			jtbKeyP.setBounds(new java.awt.Rectangle(377,95,51,22));
			jtbKeyP.setText("P");
			jtbKeyP.addActionListener(actionListener);
		}
		return jtbKeyP;
	}

	/**
	 * This method initializes jtbKeyQ	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyQ() {
		if (jtbKeyQ == null) {
			jtbKeyQ = new JToggleButton();
			jtbKeyQ.setBounds(new java.awt.Rectangle(215,123,51,22));
			jtbKeyQ.setText("Q");
			jtbKeyQ.addActionListener(actionListener);
		}
		return jtbKeyQ;
	}

	/**
	 * This method initializes jtbKeyR	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyR() {
		if (jtbKeyR == null) {
			jtbKeyR = new JToggleButton();
			jtbKeyR.setBounds(new java.awt.Rectangle(269,123,51,22));
			jtbKeyR.setText("R");
			jtbKeyR.addActionListener(actionListener);
		}
		return jtbKeyR;
	}

	/**
	 * This method initializes jtbKeyS	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyS() {
		if (jtbKeyS == null) {
			jtbKeyS = new JToggleButton();
			jtbKeyS.setBounds(new java.awt.Rectangle(323,123,51,22));
			jtbKeyS.setText("S");
			jtbKeyS.addActionListener(actionListener);
		}
		return jtbKeyS;
	}

	/**
	 * This method initializes jtbKeyT	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyT() {
		if (jtbKeyT == null) {
			jtbKeyT = new JToggleButton();
			jtbKeyT.setBounds(new java.awt.Rectangle(377,123,51,22));
			jtbKeyT.setText("T");
			jtbKeyT.addActionListener(actionListener);
		}
		return jtbKeyT;
	}

	/**
	 * This method initializes jtbKeyU	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyU() {
		if (jtbKeyU == null) {
			jtbKeyU = new JToggleButton();
			jtbKeyU.setBounds(new java.awt.Rectangle(215,151,51,22));
			jtbKeyU.setText("U");
			jtbKeyU.addActionListener(actionListener);
		}
		return jtbKeyU;
	}

	/**
	 * This method initializes jtbKeyV	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyV() {
		if (jtbKeyV == null) {
			jtbKeyV = new JToggleButton();
			jtbKeyV.setBounds(new java.awt.Rectangle(269,151,51,22));
			jtbKeyV.setText("V");
			jtbKeyV.addActionListener(actionListener);
		}
		return jtbKeyV;
	}

	/**
	 * This method initializes jtbKeyW	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyW() {
		if (jtbKeyW == null) {
			jtbKeyW = new JToggleButton();
			jtbKeyW.setBounds(new java.awt.Rectangle(323,151,51,22));
			jtbKeyW.setText("W");
			jtbKeyW.addActionListener(actionListener);
		}
		return jtbKeyW;
	}

	/**
	 * This method initializes jtbKeyX	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyX() {
		if (jtbKeyX == null) {
			jtbKeyX = new JToggleButton();
			jtbKeyX.setBounds(new java.awt.Rectangle(377,151,51,22));
			jtbKeyX.setText("X");
			jtbKeyX.addActionListener(actionListener);
		}
		return jtbKeyX;
	}

	/**
	 * This method initializes jtbKeyY	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyY() {
		if (jtbKeyY == null) {
			jtbKeyY = new JToggleButton();
			jtbKeyY.setBounds(new java.awt.Rectangle(215,179,51,22));
			jtbKeyY.setText("Y");
			jtbKeyY.addActionListener(actionListener);
		}
		return jtbKeyY;
	}

	/**
	 * This method initializes jtbKeyZ	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getJtbKeyZ() {
		if (jtbKeyZ == null) {
			jtbKeyZ = new JToggleButton();
			jtbKeyZ.setBounds(new java.awt.Rectangle(269,179,51,22));
			jtbKeyZ.setText("Z");
			jtbKeyZ.addActionListener(actionListener);
		}
		return jtbKeyZ;
	}
	
	public void selectionChanged() {
		System.out.println("SC");
	}

	/**
	 * This method initializes jButtonOK	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setBounds(new java.awt.Rectangle(356,294,81,22));
			jButtonOK.setText("OK");
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					((JDialog) getParent().getParent().getParent()).dispose();
				}
			});
		}
		return jButtonOK;
	}

	/**
	 * This method initializes jButtonCancel	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancel() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setBounds(new java.awt.Rectangle(264,294,81,22));
			jButtonCancel.setText("Cancel");
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					buttons.clear();
					((JDialog) getParent().getParent().getParent()).dispose();
				}
			});
		}
		return jButtonCancel;
	}
	
	

}  //  @jve:decl-index=0:visual-constraint="6,5"
